//
//  FYMessageView.m
//  FYAgent
//
//  Created by 于龙 on 15/11/20.
//  Copyright © 2015年 Foryou. All rights reserved.
//

#import "FYMessageView.h"

@interface FYMessageView ()
@property (weak, nonatomic) IBOutlet UIButton *warnBtn;

@end

@implementation FYMessageView

- (IBAction)warnClicked:(id)sender {
    
    if (_delegate) {
        [_delegate alertViewWarnBtnClicked:self];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    self.userInteractionEnabled = YES;
    self.warnBtn.titleLabel.font = kIconFont(18.0f);
    [self.warnBtn setTitleColor:kColorff7870 forState:UIControlStateNormal];
    [self.warnBtn setTitle:@"\U0000e613" forState:UIControlStateNormal] ;
    self.warnBtn.hidden = YES;
    
    self.rightBtn.backgroundColor = kColorff7870;
//    self.rightBtn.layer.cornerRadius = kCornerRadius;
//    self.rightBtn.layer.masksToBounds = YES;
//    self.leftBtn.backgroundColor = kWhiteColor;
//    self.leftBtn.layer.cornerRadius = kCornerRadius;
    self.leftBtn.layer.masksToBounds = YES;
    self.leftBtn.layer.borderColor = kColorc5c5c5.CGColor;
    self.leftBtn.layer.borderWidth = 1;
    
    self.signalBtn.backgroundColor = kColorff7870;
//    self.signalBtn.layer.cornerRadius = kCornerRadius;
//    self.signalBtn.layer.masksToBounds = YES;

}

- (IBAction)btnClicked:(id)sender {
    
    UIButton *btn = (UIButton *)sender;
    if (_delegate) {
        [_delegate alertView:self clickedButtonAtIndex:btn.tag];
    }
}

-(void)setAlertTitle:(NSString *)title
         warningShow:(BOOL)show
             message:(NSString *)msg
           btnTitles:(id)titles{
    
    //内容
    self.titleLabel.text = title;
    [self.titleLabel sizeToFit];
    self.messageLabel.text = msg;
    
    //问号
    self.warnBtn.hidden = !show;
 
    //按钮
    if ([titles isKindOfClass:[NSArray class]]) {  //数组
        
        NSArray *array = (NSArray *)titles;
        if (array.count == 1) {
            self.twoBtnView.hidden = YES;
            self.oneBtnView.hidden = NO;
            [self.signalBtn setTitle:array.firstObject forState:UIControlStateNormal];
            
        } else if (array.count == 2){
            self.twoBtnView.hidden = NO;
            self.oneBtnView.hidden = YES;
            [self.leftBtn setTitle:array.firstObject forState:UIControlStateNormal];
            [self.rightBtn setTitle:array.lastObject forState:UIControlStateNormal];
        }
        
    } else if ([titles isKindOfClass:[NSString class]]){ //字符串
        
        self.twoBtnView.hidden = YES;
        self.oneBtnView.hidden = NO;
        [self.signalBtn setTitle:titles forState:UIControlStateNormal];
    }
}
-(void)setAlertTitle:(NSString *)title
        attributeMsg:(NSAttributedString *)msg
           btnTitles:(id)titles{
    
    //内容
    self.titleLabel.text = title;
    [self.titleLabel sizeToFit];
    self.messageLabel.attributedText = msg;
    //按钮
    if ([titles isKindOfClass:[NSArray class]]) {  //数组
        
        NSArray *array = (NSArray *)titles;
        if (array.count == 1) {
            self.twoBtnView.hidden = YES;
            self.oneBtnView.hidden = NO;
            [self.signalBtn setTitle:array.firstObject forState:UIControlStateNormal];
            
        } else if (array.count == 2){
            self.twoBtnView.hidden = NO;
            self.oneBtnView.hidden = YES;
            [self.leftBtn setTitle:array.firstObject forState:UIControlStateNormal];
            [self.rightBtn setTitle:array.lastObject forState:UIControlStateNormal];
        }
        
    } else if ([titles isKindOfClass:[NSString class]]){ //字符串
        
        self.twoBtnView.hidden = YES;
        self.oneBtnView.hidden = NO;
        [self.signalBtn setTitle:titles forState:UIControlStateNormal];
    }
}

- (void)dealloc
{
    
}
@end
